package com.heima.crm.controller;

import com.heima.crm.common.result.Result;
import com.heima.crm.pojos.dtos.RoleDetailsDto;
import com.heima.crm.pojos.dtos.RolePageDto;
import com.heima.crm.pojos.dtos.RoleSaveDto;
import com.heima.crm.pojos.dtos.UpdateRoleDto;
import com.heima.crm.pojos.entity.TbRole;
import com.heima.crm.pojos.entity.TbRoleDetails;
import com.heima.crm.service.CrRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/role")
public class CrRoleController {

    @Resource
    private CrRoleService crRoleService;


    @PostMapping("/page")
    public Result page(@RequestBody RolePageDto rolePageDto){
        log.info("角色分页查询,{}",rolePageDto);
        return crRoleService.page(rolePageDto);
    }

    @PostMapping("/save")
    public Result save(@RequestBody RoleSaveDto roleSaveDto){
        log.info("新增角色{},{}",roleSaveDto);
        return crRoleService.saveRole(roleSaveDto);
    }

    @GetMapping("/getRole/{roleId}")
    public Result getRole(@PathVariable Long roleId){
        log.info("角色信息回显,{}",roleId);
        return crRoleService.getRole(roleId);
    }
    @PutMapping("/update")
    public Result updateRole(@RequestBody UpdateRoleDto updateRoleDto){
        log.info("修改角色:{}",updateRoleDto);
        return crRoleService.updateRole(updateRoleDto);
    }
    @DeleteMapping("/delete/{roleId}")
    public Result deleteRoleById(@PathVariable Long roleId){
        log.info("删除角色,{}",roleId);
        return crRoleService.deleteRoleById(roleId);
    }



}
